<?php

// [ 获取PK10开奖结果详情 ]
// GET pk10.detail
// http://sg.51hub.cn/api?pk10.detail
// http://sg.io/api?pk10.detail

namespace app\api\resource\pk10;
use think\Db;
use think\facade\Validate;

class Detail
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = ['member'];
    // 描述
    public $_description = '获取PK10开奖结果详情';
    // 参数
    public $_param  = [
        'no' => '期号,可选,不传获取最新的开奖结果',
    ];

    public function run(&$request)
    {
        $no = $request->param('no/d',0);

        if (0 == $no) {
            $ret = Db::name('pk10')->order('no DESC')->find();
        } else {
            if ( !Validate::regex($no,'/^\d{6}$/') ) return [422,'期号格式不正确'];
            $ret = Db::name('pk10')->where('no',$no)->find();
        }

        return [200,$ret];
    }
}
